home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / cdity / availmem2.lha / AvailMem2 / src / AvailMem2_CX.s < prev    next >
Text File  |  1997-07-01  |  10KB  |  392 lines

  1.  
  2.     machine 68020
  3.  
  4.     * program includes
  5.  
  6.     include    "AvailMem2.i"
  7.     include    "AvailMem2_gui.i"
  8.     include    "lvo.i"
  9.  
  10.     incdir    "include:"
  11.  
  12.     include    "exec/types.i"
  13.     include    "libraries/commodities.i"
  14.     include    "exec/funcdef.i"
  15.  
  16.     * program exports
  17.  
  18. CX_POPKEY        equ    1    ;CX GUI Popup key
  19.  
  20.     section    code,code        ;availmem code section
  21.  
  22. _HandleCxMsgs
  23. * * * * * * * * * * * * * * * * * * * * *
  24. *                    *
  25. * Handles all CX messages.        *
  26. *                    *
  27. * * * * * * * * * * * * * * * * * * * * *
  28.  
  29.     movem.l    d0-a6,-(sp)        ;push all registers
  30.  
  31. .MsgLoop_CxPort
  32.  
  33.     move.l    (4).w,a6        ;put execbase in a6
  34.     move.l    ptr_CxPort,a0        ;get cxport
  35.     jsr    _LVOGetMsg(a6)        ;get any waiting message
  36.     move.l    d0,ptr_TempMsg        ;store msg
  37.     beq    .no_CxPortMessages    ;if no message, continue looping
  38.  
  39.     move.l    _CommoditiesBase,a6    ;put commoditesbase in a6
  40.  
  41.     move.l    ptr_TempMsg,a4        ;put msg in a4
  42.  
  43.     move.l    a4,a0            ;put msg in a0
  44.     jsr    _LVOCxMsgID(a6)        ;get MsgID
  45.     move.l    d0,d5            ;put MsgID in d5
  46.  
  47.     move.l    a4,a0            ;put msg in a0
  48.     jsr    _LVOCxMsgType(a6)    ;get MsgID
  49.     move.l    d0,d6            ;put MsgType in d6
  50.  
  51.     cmp.l    #CXM_IEVENT,d6        ;check if program event
  52.     bne    .no_CXM_IEVENT        ;skip if not
  53.  
  54.     cmp.l    #CX_POPKEY,d5        ;check if popup-key was pressed
  55.     bne    .no_CX_POPKEY        ;skip if not
  56.  
  57.     tst.l    MemoryDisplayWnd    ;check if window open
  58.     beq    .Open_MemoryDisplayWnd_HotKey    ;skip if already open
  59.  
  60.     move.l    _IntuitionBase,a6    ;put intuitionbase in a6
  61.     move.l    MemoryDisplayWnd,a0    ;put ptr to mem-display window in a0
  62.     jsr    _LVOActivateWindow(a6)    ;activate memory-display window
  63.  
  64.     move.l    MemoryDisplayWnd,a0    ;put ptr to mem-display window in a0
  65.     jsr    _LVOWindowToFront(a6)    ;bring window to front
  66.  
  67.     bra    .no_CX_POPKEY        ;skip window opening
  68.  
  69. .Open_MemoryDisplayWnd_HotKey
  70.  
  71.     tst.l    ResizeWnd
  72.     bne    .no_CX_POPKEY
  73.  
  74.     jsr    _OpenGUI        ;open program GUI
  75.     tst.l    d0            ;check if open succeded
  76.     beq    .Fail            ;bail out if error
  77.  
  78.     clr.l    d5            ;reset MsgID
  79.  
  80. .no_CX_POPKEY
  81.  
  82.     clr.l    d6
  83.  
  84. .no_CXM_IEVENT
  85.  
  86.     cmp.l    #CXM_COMMAND,d6        ;Check if commodity event
  87.     bne    .no_CXM_COMMAND        ;skip if not
  88.  
  89.     * check for Cx events
  90.  
  91.     cmp.l    #CXCMD_ENABLE,d5    ;check if Enable command sent
  92.     bne    .no_CXCMD_ENABLE    ;skip if not
  93.  
  94.     move.l    ptr_ProgramBroker,a0    ;put program broker in a0
  95.     moveq.l    #TRUE,d0        ;set active to true
  96.     jsr    _LVOActivateCxObj(a6)    ;activate main broker
  97.  
  98. .no_CXCMD_ENABLE
  99.  
  100.     cmp.l    #CXCMD_DISABLE,d5    ;check if Disable command sent
  101.     bne    .no_CXCMD_DISABLE    ;skip if not
  102.  
  103.     move.l    ptr_ProgramBroker,a0    ;put program broker in a0
  104.     moveq.l    #FALSE,d0        ;set active to false
  105.     jsr    _LVOActivateCxObj(a6)    ;deactivate main broker
  106.  
  107. .no_CXCMD_DISABLE
  108.  
  109.     cmp.l    #CXCMD_UNIQUE,d5    ;check if Unique command sent
  110.     beq    .AppearUnique        ;goto if true
  111.  
  112.     cmp.l    #CXCMD_APPEAR,d5    ;check if Appear command sent
  113.     bne    .no_CXCMD_APPEAR    ;skip if not
  114.  
  115. .AppearUnique
  116.     tst.l    MemoryDisplayWnd    ;check if window open
  117.     beq    .Open_MemoryDisplayWnd    ;skip if already open
  118.  
  119.     move.l    _IntuitionBase,a6    ;put intuitionbase in a6
  120.     move.l    MemoryDisplayWnd,a0    ;put ptr to mem-display window in a0
  121.     jsr    _LVOActivateWindow(a6)    ;activate memory-display window
  122.  
  123.     move.l    MemoryDisplayWnd,a0    ;put ptr to mem-display window in a0
  124.     jsr    _LVOWindowToFront(a6)    ;bring window to front
  125.  
  126.     bra    .no_CXCMD_APPEAR    ;skip window opening
  127.  
  128. .Open_MemoryDisplayWnd
  129.  
  130.     tst.l    ResizeWnd
  131.     bne    .no_CXCMD_APPEAR
  132.  
  133.     jsr    _OpenGUI        ;open program GUI
  134.     tst.l    d0            ;check if open succeded
  135.     beq    .Fail            ;bail out if error
  136.  
  137.     clr.l    d5            ;reset MsgID
  138.  
  139. .no_CXCMD_APPEAR
  140.  
  141.     cmp.l    #CXCMD_DISAPPEAR,d5    ;check if Disappear command sent
  142.     bne    .no_CXCMD_DISAPPEAR    ;skip if not
  143.  
  144.     jsr    _CloseGUI        ;close program GUI
  145.     
  146.     clr.l    d5            ;reset MsgID
  147.  
  148. .no_CXCMD_DISAPPEAR
  149.  
  150.     cmp.l    #CXCMD_KILL,d5        ;check if kill-command sent
  151.     bne    .no_CXCMD_KILL
  152.  
  153.     st.l    prg_Terminate        ;enable program termination
  154.  
  155.     clr.l    d5            ;reset MsgID
  156.  
  157. .no_CXCMD_KILL
  158.  
  159.     clr.l    d6            ;reset MsgType
  160.  
  161. .no_CXM_COMMAND
  162.  
  163.     move.l    (4).w,a6        ;put execbase in a6
  164.     move.l    ptr_TempMsg,a1        ;put tempmsg in a1
  165.     jsr    _LVOReplyMsg(a6)    ;reply cx msg
  166.  
  167.     bra    .MsgLoop_CxPort        ;loop message-reader
  168.  
  169. .no_CxPortMessages
  170.  
  171.     movem.l    (sp)+,d0-a6        ;pop all registers
  172.     clr.l    d0            ;set exitcode to FALSE
  173.     rts                ;return
  174.  
  175. .Fail
  176.     movem.l    (sp)+,d0-a6        ;pop all registers
  177.     st.l    d0            ;set exitcode to TRUE
  178.     rts                ;return
  179.  
  180. _FlushPort
  181. * * * * * * * * * * * * * * * * * * * * *
  182. *                    *
  183. * Flushes the specified port from any    *
  184. * waiting messages.            *
  185. *                    *
  186. * IN:    a0 - ptr to msgport.        *
  187. *                    *
  188. * * * * * * * * * * * * * * * * * * * * *
  189.  
  190.     movem.l    d0-a6,-(sp)        ;push all registers
  191.  
  192.     move.l    (4).w,a6        ;put execbase in a6
  193.  
  194.     move.l    a0,a3            ;put msg-port in a3
  195. .MsgLoop
  196.     move.l    a3,a0            ;put msg-port in a0
  197.     jsr    _LVOGetMsg(a6)        ;get msg waiting
  198.     tst.l    d0            ;check for waiting msg
  199.     beq    .NoMsgsLeft        ;skip if no more msgs
  200.  
  201.     move.l    d0,a1            ;put msg in a1
  202.     jsr    _LVOReplyMsg(a6)    ;reply whatever msg
  203.  
  204. .NoMsgsLeft
  205.  
  206.     movem.l    (sp)+,d0-a6        ;pop all registers
  207.     rts                ;return
  208.  
  209. _AttachCXFilter
  210. * * * * * * * * * * * * * * * * * * * * *
  211. *                    *
  212. * Attaches a CX Hotkey to the program    *
  213. * CX chain.                *
  214. *                    *
  215. * IN:    a0 - ptr to hotkey combination.    *
  216. *    d0 - Event.            *
  217. *                    *
  218. * OUT:    d0 - success.            *
  219. *                    *
  220. * * * * * * * * * * * * * * * * * * * * *
  221.  
  222.     movem.l    d0-a6,-(sp)        ;push all registers
  223.  
  224.     movea.l    a0,a5            ;put hotkey in a5
  225.     move.l    d0,d7            ;put event in d7
  226.  
  227.     movea.l    a5,a0            ;put hotkey in a0
  228.     movea.l    _CommoditiesBase,a6    ;put commoditiesbase in a6
  229.     moveq    #CX_FILTER,d0        ;put CX_FILTER in d0
  230.     suba.l    a1,a1            ;no 2nd argument
  231.     jsr    _LVOCreateCxObj(a6)    ;create a filter
  232.  
  233.     movea.l    d0,a3            ;store filter in a3
  234.     move.l    a3,d0            ;check if successfull
  235.     beq.s    .Fail            ;bail out if failure
  236.  
  237.     movea.l    ptr_ProgramBroker,a0    ;put broker in a0
  238.     movea.l    a3,a1            ;put filter in a1
  239.     jsr    _LVOAttachCxObj(a6)    ;attach filter to broker
  240.  
  241.     move.l    ptr_CxPort,d0        ;put cx-port in d0
  242.     movea.l    d0,a0            ;put cx-port in a0
  243.     movea.l    d7,a1            ;put even in a1
  244.     moveq    #CX_SEND,d0        ;put CX_SEND in d0
  245.     jsr    _LVOCreateCxObj(a6)    ;create sender
  246.  
  247.     movea.l    d0,a2            ;store sender in a2
  248.     move.l    a2,d0            ;check if successfull
  249.     beq.s    .Fail            ;bail out if failure
  250.  
  251.     movea.l    a3,a0            ;put filter in a0
  252.     movea.l    a2,a1            ;put sender in a1
  253.     jsr    _LVOAttachCxObj(a6)    ;attach sender to filter
  254.  
  255.     moveq    #CX_TRANSLATE,d0    ;put CX_TRANSLATE in d0
  256.     suba.l    a0,a0            ;no 1st argument
  257.     suba.l    a1,a1            ;no 2nd argument
  258.     jsr    _LVOCreateCxObj(a6)    ;create translator
  259.  
  260.     tst.l    d0            ;check if successfull
  261.     beq.s    .Fail            ;bail out if failure
  262.  
  263.     movea.l    d0,a1            ;put translator in a1
  264.     movea.l    a3,a0            ;put filter in a0
  265.     jsr    _LVOAttachCxObj(a6)    ;attach translator to filter
  266.  
  267.     movea.l    a3,a0            ;put filter in a0
  268.     jsr    _LVOCxObjError(a6)    ;get Cx-filter errors
  269.  
  270.     tst.l    d0            ;check for ANY errors
  271.     bne.s    .Fail            ;bail out if found any
  272.  
  273.     movem.l    (sp)+,d0-a6        ;pop all registers
  274.     st.l    d0            ;set exitcode to TRUE
  275.     rts                ;return
  276.  
  277. .Fail
  278.     movem.l    (sp)+,d0-a6        ;pop all registers
  279.     clr.l    d0            ;set exitcode to FALSE
  280.     rts                ;return
  281.  
  282. _SetupCX
  283. * * * * * * * * * * * * * * * * * * * * *
  284. *                    *
  285. * Adds the program as a Cx-broker to    *
  286. * the Cx-chain.                *
  287. *                    *
  288. * OUT:    d0 - success. (=0 FAIL)        *
  289. *                    *
  290. * * * * * * * * * * * * * * * * * * * * *
  291.  
  292.     movem.l    d1-a6,-(sp)        ;push all registers
  293.  
  294.     jsr    _QuitCX            ;remove old CX (if any)
  295.  
  296.     move.l    (4).w,a6        ;put execbase in a6
  297.     jsr    _LVOCreateMsgPort(a6)    ;create a msg-port
  298.     move.l    d0,ptr_CxPort        ;store CX msg-port
  299.     beq    .Fail            ;bail out if failure
  300.  
  301.     move.l    _CommoditiesBase,a6    ;put commoditiesbase in a6
  302.     lea.l    prg_CxNewBroker,a0    ;put ptr to NewBroker in a0
  303.     move.l    ptr_ConfigName,2(a0)    ;set handler name
  304.     jsr    _LVOCxBroker(a6)    ;create program broker
  305.     move.l    d0,ptr_ProgramBroker    ;store program broker
  306.     beq    .Fail            ;bail out if failure
  307.  
  308.     move.l    ptr_PopupKey,a0        ;get ptr to popup key
  309.     move.l    #CX_POPKEY,d0        ;set event to popup key
  310.     jsr    _AttachCXFilter        ;attach hotkey
  311.     tst.l    d0            ;check if attachment succeeded
  312.     beq    .Fail            ;bail out if failure
  313.  
  314.     movem.l    (sp)+,d1-a6        ;pop all registers
  315.     st.l    d0            ;return TRUE
  316.     rts                ;return
  317.  
  318. .Fail
  319.     movem.l    (sp)+,d1-a6        ;pop all registers
  320.     clr.l    d0            ;return FALSE
  321.     rts                ;return
  322.  
  323. _QuitCX
  324. * * * * * * * * * * * * * * * * * * * * *
  325. *                    *
  326. * Removes the program Cx-broker from    *
  327. * the Cx-chain.                *
  328. *                    *
  329. * * * * * * * * * * * * * * * * * * * * *
  330.  
  331.     movem.l    d0-a6,-(sp)        ;push all registers
  332.  
  333.     tst.l    ptr_ProgramBroker    ;check if Broker installed
  334.     beq    .NoCXInstalled        ;skip if not installed
  335.  
  336.     move.l    _CommoditiesBase,a6    ;put commoditesbase in a6
  337.     move.l    ptr_ProgramBroker,a0    ;put program broker in a0
  338.     jsr    _LVODeleteCxObjAll(a6)    ;delete all Cx-objects
  339.     clr.l    ptr_ProgramBroker    ;reset ptr to broker
  340.  
  341. .NoCXInstalled
  342.  
  343.     tst.l    ptr_CxPort        ;check if msg-port installed
  344.     beq    .NoMsgPortActive    ;skip if not installed
  345.  
  346.     move.l    ptr_CxPort,a0        ;put ptr to port in a0
  347.     jsr    _FlushPort        ;flush the port from all messages
  348.     move.l    (4).w,a6        ;put execbase in a6
  349.     jsr    _LVODeleteMsgPort(a6)    ;delete the msg-port
  350.     clr.l    ptr_CxPort        ;reset ptr to port
  351.  
  352. .NoMsgPortActive
  353.  
  354.     movem.l    (sp)+,d0-a6        ;pop all registers
  355.     rts                ;return
  356.  
  357.     section    data,data        ;availmem data section
  358.  
  359. * CX strings
  360.  
  361. _ProgramTitle        dc.b    "AvailMem2 © 1996-97 Jesper Svennevid",0
  362. _ProgramDescr        dc.b    "Displays your memory! :)",0
  363. _DefaultPopup        dc.b    "control lalt a",0
  364.  
  365.     cnop    0,8
  366.  
  367. * CX NewBroker
  368.  
  369. prg_CxNewBroker
  370.     dc.b    NB_VERSION        ;version
  371.     dc.b    0            ;Reserve1
  372.     dc.l    0            ;Handler name
  373.     dc.l    _ProgramTitle        ;Title
  374.     dc.l    _ProgramDescr        ;Description
  375.     dc.w    NBU_NOTIFY!NBU_UNIQUE    ;Unique
  376.     dc.w    COF_SHOW_HIDE        ;Flags
  377. prg_CxPri
  378.     dc.b    0            ;Pri
  379.     dc.b    0            ;Reserve2
  380. ptr_CxPort
  381.     dc.l    0            ;BrokerPort
  382.     dc.w    0            ;Reserved channel
  383.  
  384.     section    bss,bss            ;availmem bss section
  385.  
  386. * program variables
  387.  
  388. ptr_ProgramBroker    ds.l    1    ;ptr to program CX-broker
  389. ptr_PopupKey        ds.l    1    ;ptr to program popup key
  390.  
  391. prg_Popup        ds.l    1    ;program start-popup variable
  392.